var gl_vue_vm_list_firstPre_html = $('#vue_vm_list_firstPre').html();
var gl_vue_vm_list_pre_html = $('#vue_vm_list_pre').html();

$(function() {
	$('#vue_vm_list_firstPre').hide();
	$('#vue_vm_list_pre').hide();
});

window.onload = function() {
	mealCard_findElderFirstPreList();
	mealCard_findElderPreList();
}

function mealCard_findElderFirstPreList() {
	if($('#vue_vm_list_firstPre').length==0) {return;}
	$('#vue_vm_list_firstPre').hide();
	
	findAll_basic(path+'/mealCard/findElderFirstPreList', function(response) {	
		$('#vue_vm_list_firstPre').html(gl_vue_vm_list_firstPre_html);
		
		for(i=0; i<response.data.length; i++) {
			response.data[i].money = 450;
		}
		
		new Vue({
			el: '#vue_vm_list_firstPre',
			data: {
				todos: response.data
			},
			methods: {
				getNowDiff: function(sDate1) {
					var nowDate = getNowFormatDate().substr(0,10);
					return DateDiff(nowDate, sDate1);
				},
				getSubsidizationValue:function(subsidization, subsidizationValue) {
					return getSubsidizationValue(subsidization, subsidizationValue);
				},
				getSubsidizationUnit:function(subsidization) {
					return getSubsidizationUnit(subsidization);
				},
				getSubsidizationText:function(subsidization, subsidizationValue) {
					return getSubsidizationText(subsidization, subsidizationValue);
				},
				getConsDeductionText:function(consumptionWay, consDeductionWay) {
					return getConsDeductionText(consumptionWay, consDeductionWay);
				},
				//总共可扣月数
				getTotalMonths:function(todo) {
					return getTotalMonths(todo);
				},
				//剩余可扣月数
				getRemainMonths:function(todo) {
					return getRemainMonths(todo);
				},
				//已扣月数
				getAlreadyUsedMonths:function(todo) {
					return getAlreadyUsedMonths(todo);
				},
				//总共可扣天数
				getTotalNumber:function(todo) {
					return getTotalNumber(todo);
				},
				//剩余可扣天数
				getRemainNumber:function(todo) {
					return getRemainNumber(todo);
				},
				//已扣天数
				getAlreadyUsedNumber:function(todo) {
					return getAlreadyUsedNumber(todo);
				},
				getChepingUrl:function(elderId, elderName, elderCardId) {
					return getChepingUrl(elderId, elderName, elderCardId);
				},
				mealCard_resetPreBalance:function(todo) {
					if(confirm('确实要把赠送余额清0吗？')) {
						save_basic_by_json(path+'/mealCard/resetPreBalance', {id:todo.mealCardId}, function() {
							$('#'+todo.mealCardId+'_resetPreBalance_button').remove();
							alert('赠送余额清0成功');
						});
					}
				},
				mealCard_rechargePreBalance:function(todo) {
					if(confirm('确实要把赠送余额清0并赠送本月补助吗？')) {
						save_basic_by_json(path+'/mealCard/rechargePreBalance', {id:todo.mealCardId, money:todo.money}, function() {
							$('#'+todo.mealCardId+'_rechargePreBalance_button').remove();
							alert('清0并赠送本月补助成功');
						});
					}
				}
			}
		});
		
		$('#vue_vm_list_firstPre').show();
	});
}

function mealCard_findElderPreList() {
	if($('#vue_vm_list_pre').length==0) {return;}
	$('#vue_vm_list_pre').hide();
	
	findAll_basic(path+'/mealCard/findElderPreList', function(response) {	
		$('#vue_vm_list_pre').html(gl_vue_vm_list_pre_html);
		
		for(i=0; i<response.data.length; i++) {
			response.data[i].money = 450;
		}
		
		new Vue({
			el: '#vue_vm_list_pre',
			data: {
				todos: response.data
			},
			methods: {
				getNowDiff: function(sDate1) {
					var nowDate = getNowFormatDate().substr(0,10);
					return DateDiff(nowDate, sDate1);
				},
				getSubsidizationValue:function(subsidization, subsidizationValue) {
					return getSubsidizationValue(subsidization, subsidizationValue);
				},
				getSubsidizationUnit:function(subsidization) {
					return getSubsidizationUnit(subsidization);
				},
				getSubsidizationText:function(subsidization, subsidizationValue) {
					return getSubsidizationText(subsidization, subsidizationValue);
				},
				getConsDeductionText:function(consumptionWay, consDeductionWay) {
					return getConsDeductionText(consumptionWay, consDeductionWay);
				},
				//总共可扣月数
				getTotalMonths:function(todo) {
					return getTotalMonths(todo);
				},
				//剩余可扣月数
				getRemainMonths:function(todo) {
					return getRemainMonths(todo);
				},
				//已扣月数
				getAlreadyUsedMonths:function(todo) {
					return getAlreadyUsedMonths(todo);
				},
				//总共可扣天数
				getTotalNumber:function(todo) {
					return getTotalNumber(todo);
				},
				//剩余可扣天数
				getRemainNumber:function(todo) {
					return getRemainNumber(todo);
				},
				//已扣天数
				getAlreadyUsedNumber:function(todo) {
					return getAlreadyUsedNumber(todo);
				},
				getChepingUrl:function(elderId, elderName, elderCardId) {
					return getChepingUrl(elderId, elderName, elderCardId);
				},
				mealCard_resetPreBalance:function(todo) {
					if(confirm('确实要把赠送余额清0吗？')) {
						save_basic_by_json(path+'/mealCard/resetPreBalance', {id:todo.mealCardId}, function() {
							$('#'+todo.mealCardId+'_resetPreBalance_button').remove();
							alert('赠送余额清0成功');
						});
					}
				},
				mealCard_rechargePreBalance:function(todo) {
					if(confirm('确实要把赠送余额清0并赠送本月补助吗？')) {
						save_basic_by_json(path+'/mealCard/rechargePreBalance', {id:todo.mealCardId, money:todo.money}, function() {
							$('#'+todo.mealCardId+'_rechargePreBalance_button').remove();
							alert('清0并赠送本月补助成功');
						});
					}
				}
			}
		});
		
		$('#vue_vm_list_pre').show();
	});
}